import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import com.manolo.framework.deck.Card;
import com.manolo.framework.deck.SUIT;

public class TestObjectToJson {
	private int data1;
	
	private String data2;
	
	private List<Card> lista;

	public int getData1() {
		return data1;
	}

	public String getData2() {
		return data2;
	}

	public void setData1(int data1) {
		this.data1 = data1;
	}

	public void setData2(String data2) {
		this.data2 = data2;
	}
	
	public TestObjectToJson() {
		lista = new ArrayList<Card>();
	}

	public static void main(String[] args) {

		TestObjectToJson obj = new TestObjectToJson();
		obj.setData1(1);
		obj.setData2("gustavo");
		obj.lista.add(new Card(1, SUIT.CLUBS,2));
		obj.lista.add(new Card(1, SUIT.DIAMONDS,1));
		
		Gson gson = new Gson();

		// convert java object to JSON format
		String json = gson.toJson(obj);

		System.out.println(json);
		// json data
//		String json2 = "{'data1':100,'data2':'hello'}";
		

		// convert JSON into java object
		TestObjectToJson obj2 = gson.fromJson(json, TestObjectToJson.class);
		System.out.println(obj2);
		System.out.println(obj2.getData2());
		
		obj2.getClass().getFields();
		
		java.lang.reflect.Field[] campos = obj2.getClass().getDeclaredFields();
		System.out.println(campos[0].getName());
		
	}

	@Override
	public String toString() {
		return "TestJsonFromObject [data1=" + data1 + ", data2=" + data2 + "]";
	}

}